//
//  shuhuiSuccessViewController.m
//  HaoDeCaiFu
//
//  Created by 张玉鹏 on 2017/11/24.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "shuhuiSuccessViewController.h"
#import "jijinShuhuiResultTableViewCell.h"

@interface shuhuiSuccessViewController ()
@property(nonatomic,strong)UIImageView *headerView;

@end

@implementation shuhuiSuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title=@"赎回";

    [self.tableView setTableHeaderView:self.headerView];
    
    [self configerBottomView];
}

-(void)configerBottomView
{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, screenHeight - 49 , screenWidth, 49);
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(jumpBuy) forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundColor:ZKcolor(184, 27, 36)];
    [self.view addSubview:btn];
}
#pragma mark -
#pragma mark 点击事件
//立即购买
-(void)jumpBuy
{
    [self.navigationController popToRootViewControllerAnimated:YES];
//    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
}
#pragma mark -
#pragma mark initView
-(UITableView*)tableView
{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight-49)];
        _tableView.backgroundColor=ZKcolor(243, 243, 243);
        _tableView.dataSource=self;
        _tableView.delegate=self;
        _tableView.sectionHeaderHeight=W_RATIO(100);
        _tableView.sectionFooterHeight=W_RATIO(30);
        [self.view addSubview: _tableView];
        [_tableView setTableFooterView:[[UIView alloc]initWithFrame:CGRectZero]];
         [_tableView registerNib:[UINib nibWithNibName:@"jijinShuhuiResultTableViewCell" bundle:nil] forCellReuseIdentifier:@"jijinShuhuiResultTableViewCell"];
        
        
    }
    return _tableView;
}
-(UIImageView*)headerView
{
    if (!_headerView) {
        _headerView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, W_RATIO(220))];
        _headerView.backgroundColor=[UIColor whiteColor];
        _headerView.image=[UIImage imageNamed:@"yitijiao"];
        _headerView.contentMode=UIViewContentModeScaleAspectFit;
        
    }
    return _headerView;
}
#pragma mark -
#pragma mark UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.shuhuiModel.sellResult.count;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    jijinShuhuiResultTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"jijinShuhuiResultTableViewCell" forIndexPath:indexPath];
    shuhuiResultModel*model=self.shuhuiModel.sellResult[indexPath.row];
   
    if ([[NSString stringWithFormat:@"%@",model.transactionStatus] isEqualToString:@"received"]) {
        cell.nameLable.text=model.fundName;
        
        cell.resultLable.text=[NSString stringWithFormat:@"下单时间：%@",[self shijianChuoZhuanshijianWith:model.orderDate]];
        cell.yuanyinLable.text=[NSString stringWithFormat:@"预计到账时间：%@",[self shijianChuoZhuanshijianWith:model.expectedDealDate]];
    }
    else if ([model.transactionStatus isEqualToString:@"void"])
    {
        cell.nameLable.text=model.fundName;
        cell.nameLable.textColor=COLOR_NAV;
        cell.resultLable.textColor=COLOR_NAV;
        cell.yuanyinLable.textColor=COLOR_NAV;
        cell.resultLable.text=[NSString stringWithFormat:@"赎回失败"];
        cell.yuanyinLable.text=[NSString stringWithFormat:@"%@",model.reason];
        
    }
    
    
    return cell;
}
//时间戳转化为时间
-(NSString*)shijianChuoZhuanshijianWith:(NSString*)TimeStr
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[TimeStr doubleValue] / 1000];
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    return confromTimespStr;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
